import { UserService } from '@/apis/user';
import { defineStore } from 'pinia';

export const useUserStore = defineStore('user', () => {
  const userInfo = ref<UserApiResp.UserInfo>();
  const isFetched = ref<boolean>(false);
  async function fetchUserInfoAction(): Promise<boolean> {
    try {
      const { data } = await UserService.fetchUserInfo();
      userInfo.value = data;
      isFetched.value = true;
      return true;
    } catch {
      isFetched.value = false;
      return false;
    }
  }

  return {
    userInfo,
    isFetched,
    fetchUserInfoAction,
  };
});
